#include <cstdio>

int main() {
    const int MAX = 100000;
    int d[MAX+10] = {0};
    int n, m, sum = 0;
    int source, target;
    int distance;

    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &d[i]);
        sum += d[i];
        d[i] = sum;
    }

    scanf("%d", &m);
    for (int i = 0; i < m; i++) {
        scanf("%d%d", &source, &target);
        if (source > target) {
            source = source ^ target;
            target = source ^ target;
            source = source ^ target;
        }
        distance = d[target-1] - d[source-1];
        printf("%d\n", distance > sum - distance ? sum - distance : distance);
    }

    return 0;
}